<?php

namespace App\Models;


class Goods extends CommonModel
{
    //
    protected $table = 'shop_goods';

    public function param_options()
    {
        $params = [];
        $params['status'] = [
            "1" => '上架',
            "2" => '下架'
        ];
        return $params;
    }

    /**
     * 关联店铺信息
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function shop()
    {
        return $this->belongsTo(Shop::class, 'shop_id', 'id');
    }

    /**
     * 根据商家ID获取商品列表
     *
     * @param $shopid
     * @return mixed
     */
    public static function getByShopId($shopid)
    {
        return self::where(['shop_id' => $shopid, 'is_delete' => 0, 'status' => 1])->get();
    }

    /**
     * 判断是否存在某个宝贝ID的信息
     *
     * @param $iid
     * @param int $id
     * @return bool
     */
    public static function isExist($iid, $id = 0)
    {
        $data = self::where(['item_id' => $iid, 'is_delete' => 0])->when($id, function ($query) use ($id) {
            $query->where('id', '!=', $id);
        })->first();
        return is_null($data) ? false : true;
    }
}
